//
//  ThirdViewController.swift
//  WaiBao
//
//  Created by 赵佟越 on 17/5/11.
//  Copyright © 2017年 zhaotongyue. All rights reserved.
//

import UIKit
import Eureka
import SnapKit

class ThirdViewController: FormViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        makeBaseUI()
        layoutNavigation()
               // Do any additional setup after loading the view.
    }
    //MARK: - Private Methods
    func makeBaseUI(){
        form +++ Section("Section1")
            //为区域添加一个标签行
            <<< LabelRow("LabelRow"){
                $0.title = $0.tag
                $0.value = "tap the row111"
                }//选中标签行会在tittle后面加上" Summer "
                .onCellSelection{cell, row in
                    row.title = (row.title ?? "") + " Summer "
                    row.reload()
            }
            //为区域添加一个日期行。点击日期行会在屏幕底部弹出一个日期选择器
            <<< DateRow("dataRow"){
                $0.value = NSDate() as Date
                $0.title = "DateRow"
            }.onChange({ (row) in
                print(row.value!)
            })
            //为区域添加一个勾选行，默认为选中
            <<< CheckRow("1"){
                $0.title = "CheckRow"
                $0.value = true
            }.onCellSelection({ (cell, row) in
                
            })
            //为区域添加一个开关行，默认为开
            <<< SwitchRow("2"){
                $0.title = "SwitchRow"
                $0.value = true
            }
            //为区域添加一个滑动条行，默认值为5
            <<< SliderRow("3"){
                $0.title = "SliderRow"
                $0.value = 5.0
            }
            //为区域添加一个增减器行，每次增减的大小为1
            <<< StepperRow("4"){
                $0.title = "StepperRow"
                $0.value = 10.0
        }
            <<< SegmentedRow<String>("sex"){
                $0.options = ["男", "女"]
                $0.title = "性別"
                $0.value = "男"
                }.onChange{ row in
                    let userDefault = UserDefaults.standard
                    userDefault.setValue(row.value, forKey: "Sex")
        }.cellUpdate({ (cell, row) in
            cell.segmentedControl.setWidth(30, forSegmentAt: 1)
            cell.segmentedControl.setWidth(30, forSegmentAt: 0)
            cell.titleLabel?.snp.makeConstraints({ (make) in
                make.right.equalTo(cell).offset(-100)
                make.left.equalTo(cell).offset(15)
                make.top.bottom.equalTo(cell)
            })
        })
        
    }
    func layoutNavigation(){
        self.title = "第三页"
        let rightBtn = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done,
                                       target: self, action: #selector(ThirdViewController.onRemove))
        //设置导航项右边的按钮
        self.navigationItem.setRightBarButton(rightBtn, animated: true)
        
    }
   
    
    //MARK: - ButtonAction
    func onRemove(){
        print("123")
        print(form.values())
        let dic = form.values()
        print(dic["LabelRow"]!!)
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
